package com.kitty.game.reward.model;

import com.kitty.game.utils.Const;
import lombok.Getter;
import lombok.Setter;
import org.codehaus.jackson.annotate.JsonIgnore;

@Setter
@Getter
public class RewardUnitSet {
    private byte type;
    private String showName;
    private String name;
    private short level;
    private int count;
    private byte bind;

    private int storeType;//存储类型 0:不占用背包，1:独占一格，2可以叠加


    @JsonIgnore
    private String desc;

    public RewardUnitSet() {}

    public RewardUnitSet(byte type, String name, short level, int count, byte bind, int storeType) {
        this.type = type;
        this.name = name;
        this.level = level;
        this.count = count;
        this.bind = bind;
        this.storeType = storeType;
    }

    public String getDesc() {
        if (desc == null) {
            initDesc();
        }
        return desc;
    }

    public void initDesc() {
        // #I物品|血池#r1%bind#I#I物品|灵池#r1%bind#I
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("#I").append(getTypeName())
                .append("|").append(getShowName() != null ? getShowName() : getName());

        if (level > 0) {
            stringBuilder.append("$").append(level);
        }

        if (count > 0) {
            stringBuilder.append("#r").append(count);
        }

        if (bind == 1) {
            stringBuilder.append("%bind");
        }

        stringBuilder.append("#I");

        desc = stringBuilder.toString();
    }

    public String getTypeName() {
        switch (type) {
            /**道具*/
            case Const.REWARD_TYPE_ITEM:
                return "物品";
            /**首饰*/
            case Const.REWARD_TYPE_JEWELRY:
                return "首饰";
            /**代金券*/
            case Const.REWARD_TYPE_VOUCHER:
                return "代金券";
            case Const.REWARD_TYPE_PET:
                return "宠物";
            case Const.REWARD_TYPE_ARTIFACT:
                return "法宝";
            case Const.REWARD_TYPE_yinde:
                return "阴德";
            case Const.REWARD_TYPE_hunqi:
                return "物品";
            case Const.REWARD_TYPE_jinbi:
                return "金币";
            case Const.REWARD_TYPE_luoshuexp:
                return "洛书经验";
            case Const.REWARD_TYPE_wulingzhi:
                return "武灵值";
            case Const.REWARD_TYPE_guiqi:
                return "鬼气";
            case Const.REWARD_TYPE_jinyuanbao:
                return "金元宝";
            case Const.REWARD_TYPE_yinyuanbao:
                return "银元宝";
            case Const.REWARD_TYPE_banggong:
                return "帮贡";

        }

        throw new RuntimeException("无法识别类型:" + type);
    }

    /**获得需要格子数量*/
    public int getPosCount() {
        if (type == Const.REWARD_TYPE_VOUCHER || type == Const.REWARD_TYPE_GUARD
                || type == Const.REWARD_TYPE_PET || type == Const.REWARD_TYPE_yinde) {
            return 0;
        }
        return 1;
    }

    /**获得需要宠物格子数量*/
    public int getPetPosCount() {
        if (type == Const.REWARD_TYPE_PET) {
            return 1;
        }
        return 0;
    }
}
